home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / football / exec / changematchscore.rexx < prev    next >
OS/2 REXX Batch file  |  1999-11-29  |  11KB  |  479 lines

  1. /* ***********************************************************************
  2.  
  3.    CHANGE MATCH SCORE PROGRAM FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------------------
  5.                    Copyright  Mark Naughton 1999
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  
  11.  1.0       260999   Created. Changes scores within the datafiles.
  12.            021099   Added code to allow user to select from a duplicate
  13.                     match list.
  14.            031099   Changed format of matches written out if duplicated.
  15.                     Changed date format.
  16.  
  17. **************************************************************************
  18.  
  19. Procedure
  20. ---------
  21.  
  22. 1. Check files.
  23. 2. Read sflearn file into an array.
  24. 3. Read player stats into an array, if it exists.
  25. 4. Write new sflearn file, inserting new data.
  26. 5. Read sf file into an array.
  27. 6. Check for duplicates, if found, write to a file.
  28. 7. Using an external program, select the correct match.
  29. 8. Read response from written file.
  30. 9. Check sf array, overwriting the correct match.
  31. 10.Write new sf data to a file.
  32. 11.Display report.
  33.  
  34. ************************************************************************** */
  35. PARSE ARG league_stuff
  36.  
  37. version      = 1
  38. input_file   = '.sflearn'
  39. input2_file  = '.sf'
  40. input3_file  = '.df'
  41. details_file = 'RAM:Match.details'
  42. separator    = '*'
  43. selines.     = '???'
  44. secount      = 0
  45. dets.        = '???'
  46. det_ct       = 0
  47. not_played   = '__   __'
  48. league_file  = "Data/"league_file
  49. dupmats.     = '???'
  50.  
  51.  
  52. if open(datafile,"Data/Football.locale",'r') then do
  53.    line = readln(datafile)
  54.    locdir = strip(line)
  55.    close(datafile)
  56. end
  57. else do
  58.    say
  59.    say "ERROR :    (ChangeMatchScore)"
  60.    say
  61.    say "Cannot read 'Data/Football.locale' for the locale settings."
  62.    exit
  63. end
  64.  
  65. locdir = locdir"Exec/ChangeMatchScore.data"
  66.  
  67. if open(datafile,"ENV:FootballRXPath",'r') then do
  68.    line = readln(datafile)
  69.    rxdir = strip(line)
  70.    close(datafile)
  71. end
  72. else
  73.    rxdir = "SYS:Rexxc/"
  74.  
  75. if exists(locdir) > 0 then do
  76.   address command rxdir'rx 'locdir
  77.   VarCount = getclip('VarCount')
  78.   do i = 1 to VarCount
  79.     interpret getclip('var.'i)
  80.   end
  81. end
  82. else do
  83.    say
  84.    say "ERROR :    (ChangeMatchScore)"
  85.    say
  86.    say "Cannot find '"locdir"' to read locale settings."
  87.    exit
  88. end
  89.  
  90. addlib('rexxsupport.library',0,-30,0)
  91.  
  92. parse var league_stuff league_file match
  93. parse var match "*" tt1 "*" ss1 "*" ss2 "*" tt2 "*" mkrms
  94.  
  95. league_file = "Data/"strip(league_file)
  96. unplay = 0
  97. if strip(ss1) = "__" then unplay = 1
  98.  
  99. if exists(league_file || input_file) = 0 then do
  100.    say
  101.    say cms_error
  102.    say
  103.    say cms_one"'"league_file||input_file"'."
  104.    exit
  105. end
  106.  
  107. if exists(league_file || input2_file) = 0 then do
  108.    say
  109.    say cms_error
  110.    say
  111.    say cms_one"'"league_file||input2_file"'."
  112.    exit
  113. end
  114.  
  115. if exists(league_file || input3_file) = 0 then do
  116.    say
  117.    say cms_error
  118.    say
  119.    say cms_one"'"league_file || input3_file"'."
  120.    exit
  121. end
  122.  
  123. if open(datafile,league_file || input3_file,'r') then do
  124.    do while ~eof(datafile)
  125.       line = readln(datafile)
  126.       if pos("*LEAGUE_NAME=",line) > 0 then
  127.          parse var line "*LEAGUE_NAME=" league_name
  128.    end
  129.    close(datafile)
  130. end
  131. else do
  132.    say
  133.    say cms_error
  134.    say
  135.    say cms_two"'"league_file || input3_file"'"cms_three
  136.    exit
  137. end
  138.  
  139. secount = 0
  140. if open(datafile3,league_file || input_file,'r') then do
  141.    do while ~eof(datafile3)
  142.       line = readln(datafile3)
  143.       if line ~= "" then do
  144.          secount         = secount + 1
  145.          selines.secount = strip(line)
  146.       end
  147.    end
  148.    close(datafile3)
  149. end
  150. else do
  151.    say
  152.    say cms_error
  153.    say
  154.    say cms_two"'"league_file || input_file"' "cms_three
  155.    exit
  156. end
  157.  
  158. if exists(details_file) > 0 then do
  159.    parse value statef(details_file) with . fsize .
  160.    if fsize > 0 then do
  161.       if open(datafile4,details_file,'r') then do
  162.          do while ~eof(datafile4)
  163.             line = readln(datafile4)
  164.             if line ~= "" then do
  165.                det_ct      = det_ct + 1
  166.                dets.det_ct = strip(line)
  167.             end
  168.          end
  169.          close(datafile4)
  170.          players = 1
  171.       end
  172.       else do
  173.          say
  174.          say cms_error
  175.          say
  176.          say cms_two"'"details_file"' "cms_three
  177.          exit
  178.       end
  179.    end
  180.    else
  181.       players = 0
  182. end
  183. else
  184.    players = 0
  185.  
  186. tt1 = strip(tt1)
  187. tt2 = strip(tt2)
  188. ss1 = strip(ss1)
  189. ss2 = strip(ss2)
  190. mkm = 0
  191. mka = 0
  192.  
  193. if open(datafile3,league_file || input_file,'w') then do
  194.    do i=1 to secount
  195.       if pos(separator,selines.i) = 0 then
  196.          mkm = mkm + 1
  197.       if mkm > mkrms then
  198.          mka = 0
  199.       if mkm = mkrms & mka = 0 then do
  200.          mka = 1
  201.          stored_match = selines.i
  202.          if unplay = 0 then do
  203.             writeln(datafile3,left(tt1,30," ")" "right(ss1,2," ")"   "right(ss2,2," ")"  "tt2)
  204.             if players = 1 then do
  205.                do jk=1 to det_ct
  206.                   if dets.jk ~= "" & dets.jk ~= "???" then
  207.                      writeln(datafile3,strip(dets.jk))
  208.                end
  209.             end
  210.          end
  211.       end
  212.       if mka = 1 & selines.i == "*" then
  213.          writeln(datafile3,"*")
  214.       if mka = 0 & selines.i ~= "???" & selines.i ~= "" then
  215.          writeln(datafile3,selines.i)
  216.    end
  217.    close(datafile3)
  218. end
  219. else do
  220.    say
  221.    say cms_error
  222.    say
  223.    say cms_two"'"league_file || input_file"' "cms_four
  224. end
  225.  
  226. secount = 0
  227. if open(datafile3,league_file || input2_file,'r') then do
  228.    do while ~eof(datafile3)
  229.       line = readln(datafile3)
  230.       secount         = secount + 1
  231.       selines.secount = strip(line)
  232.    end
  233.    close(datafile3)
  234. end
  235. else do
  236.    say
  237.    say cms_error
  238.    say
  239.    say cms_two"'"league_file || input2_file"' "cms_three
  240.    exit
  241. end
  242.  
  243. ocrs = 0
  244. numberm = "##NONE##"
  245. do i=1 to secount
  246.    if pos("*Week",selines.i) > 0 then do
  247.       parse var selines.i "*Week" . numberm
  248.       numberm = "Week "strip(numberm)
  249.    end
  250.    if pos("*Date",selines.i) > 0 then do
  251.       parse var selines.i "*Date" . numbern
  252.       numberm = strip(DateFormat(numbern))
  253.    end
  254.    if numberm = "##NOT FOUND##" then do
  255.       say
  256.       say cms_error
  257.       say
  258.       say cms_t12
  259.       exit
  260.    end
  261.    if strip(stored_match) == strip(selines.i) then do
  262.       ocrs = ocrs + 1
  263.       if numberm = "##NONE##" then
  264.          numberm = ocrs
  265.       numberm = "("numberm")"
  266.       t1 = right(strip(substr(selines.i,1,30)),30,' ')
  267.       m1 = t1||substr(selines.i,31)
  268.       dupmats.ocrs = numberm" "strip(m1)
  269.       numberm = "##NONE##"
  270.    end
  271. end
  272.  
  273. if ocrs > 1 then do
  274.    if open(datafile3,"RAM:DupMatches",'w') then do
  275.       do j=1 to ocrs
  276.          writeln(datafile3,dupmats.j)
  277.       end
  278.       close(datafile3)
  279.    end
  280.    else do
  281.       say
  282.       say cms_error
  283.       say
  284.       say cms_two"'RAM:DupMatches' "cms_four
  285.       exit
  286.    end
  287.  
  288.    address command 'Exec/DupMatches'
  289.    address command 'c:Delete >NIL: RAM:DupMatches'
  290.  
  291.    if open(datafile3,"RAM:DupMat.selection",'r') then do
  292.       do while ~eof(datafile3)
  293.          line = readln(datafile3)
  294.          if line ~= "" then
  295.             selmat = strip(line)
  296.       end
  297.       close(datafile3)
  298.       address command 'c:Delete >NIL: RAM:DupMat.selection'
  299.    end
  300.    else do
  301.       say
  302.       say cms_error
  303.       say
  304.       say cms_two"'RAM:DupMat.selection' "cms_three
  305.       exit
  306.    end
  307. end
  308. else
  309.    selmat = 1
  310.  
  311. ocrsg = 0
  312. do i=1 to secount
  313.    if strip(stored_match) == strip(selines.i) then do
  314.       ocrsg = ocrsg + 1
  315.       if ocrsg = selmat then do
  316.          selines.i = left(tt1,30," ")" "right(ss1,2," ")"   "right(ss2,2," ")"  "tt2
  317.          leave
  318.       end
  319.    end
  320. end
  321.  
  322. if open(datafile3,league_file || input2_file,'w') then do
  323.    do j=1 to secount
  324.       if j = secount then
  325.          writech(datafile3,selines.j)
  326.       else
  327.          writeln(datafile3,selines.j)
  328.    end
  329.    close(datafile3)
  330. end
  331. else do
  332.    say
  333.    say cms_error
  334.    say
  335.    say cms_two"'"league_file || input2_file"' "cms_four
  336.    exit
  337. end
  338.  
  339. if exists(details_file) > 0 then
  340.    address command 'delete >NIL: 'details_file
  341.  
  342. say
  343. say center(cms_five,78)
  344. say "-------------------------------------------------------------------------------"
  345. say
  346. say
  347. say cms_t1" : "strip(league_name)
  348. say
  349. say
  350. say cms_t2
  351. uline = ""
  352. do k=1 to length(cms_t2)
  353.    uline = uline"-"
  354. end
  355. say uline
  356. say
  357. say stored_match
  358. say
  359. say
  360. say cms_t3
  361. uline = ""
  362. do k=1 to length(cms_t3)
  363.    uline = uline"-"
  364. end
  365. say uline
  366. say
  367. say left(tt1,30," ")" "right(ss1,2," ")"   "right(ss2,2," ")"  "tt2
  368. say
  369. say
  370. if unplay = 0 then
  371.    say cms_t4" : "cms_t5
  372. else
  373.    say cms_t4" : "cms_t6
  374. if players = 1 then do
  375.    say
  376.    say cms_t11
  377. end
  378. say
  379. say
  380. say "-------------------------------------------------------------------------------"
  381.  
  382. exit
  383.  
  384.  
  385. /* Procedure --------------------------------------------------------- */
  386.  
  387. DateFormat :
  388. parse arg datetoform
  389.  
  390.  
  391. s_l = 0
  392. dateall = datetoform
  393.  
  394. search_loc = strip(word(dateall,words(dateall)-1))
  395. do mnls=1 to 12
  396.    if pos(word(months,mnls),search_loc) > 0 then do
  397.       s_l = 1
  398.       leave
  399.    end
  400. end
  401. if s_l = 0 then do
  402.    locale_cats = showdir("Locale/")
  403.    do search_locale=1 to words(locale_cats)
  404.       dfordir = "Locale/"word(locale_cats,search_locale)"/Football.locale_data"
  405.       if exists(dfordir) > 0 then do
  406.         address command rxdir'rx 'dfordir
  407.         VarCount = getclip('VarCount')
  408.         do i = 1 to VarCount
  409.           interpret getclip('var.'i)
  410.         end
  411.       end
  412.       dateall = datetoform
  413.       search_loc = strip(word(dateall,words(dateall)-1))
  414.       do mnls=1 to 12
  415.          if pos(word(months,mnls),search_loc) > 0 then do
  416.             s_l = 1
  417.             leave
  418.          end
  419.       end
  420.       if s_l = 1 then leave
  421.    end
  422. end
  423. if s_l > 0 then do
  424.    temp_dtal = dateall
  425.    parse var date_format "day" sp1 "number" sp2 "month" sp3 "year"
  426.    dateall = datetoform
  427.    do i=1 to 7
  428.       if pos(word(days,i),dateall) > 0 then do
  429.          lk = pos(word(days,i),dateall)
  430.          dateall = delstr(dateall,1,lk+length(word(days,i))+length(sp1)-1)
  431.       end
  432.    end
  433.    dateall = strip(dateall)
  434.    year = word(dateall,words(dateall))
  435.    mnth = strip(word(dateall,words(dateall)-1))
  436.    do lm=1 to length(mnth)
  437.       if datatype(substr(mnth,1,1),'m') ~= 1 then
  438.          mnth = delstr(mnth,1,1)
  439.    end
  440.    dateall = temp_dtal
  441.    day  = word(dateall,2)
  442.    do lm=1 to length(day)-2
  443.       if datatype(substr(day,3,1),'n') ~= 1 then
  444.          day = delstr(day,3,1)
  445.    end
  446.    cv = 0
  447.    do i=1 to 12
  448.       if pos(word(months,i),mnth) > 0 then do
  449.          cv = i
  450.          leave
  451.       end
  452.    end
  453. end
  454. if s_l = 0 then return "##NOT FOUND##"
  455.  
  456. sd   = year||right(cv,2,0)||right(day,2,0)
  457. search_date = date('b',sd,'s')
  458. return getweek(search_date)
  459.  
  460.  
  461. /* Procedure --------------------------------------------------------- */
  462.  
  463. getweek:
  464. parse arg days
  465.  
  466. dd = days - 722450
  467. dd = date('n',dd,'i')
  468. dd = delstr(dd,8,2)
  469. parse var dd dy mn yy
  470.  
  471. dy = strip(dy)
  472. mn = strip(mn)
  473. yy = strip(yy)
  474. parse var date_format "day" sp1 "number" sp2 "month" sp3 "year"
  475. dd = dy||sp2||mn||sp3||yy
  476. return dd
  477.  
  478.  
  479. /* *********************************************************************** */